package pwd.allen.util;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DateUtil {
	public static String getTimeStamp() {
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String timeStamp = simpleDateFormat.format(date);
		return timeStamp;
	}

	/**
	 * 已指定格式获取某个时间区间中时间字符串
	 * @param dateBegin
	 * @param dateEnd
	 * @param dateFormat
	 * @return
	 */
	public static List<String> getDateSequence(LocalDate dateBegin, LocalDate dateEnd, String dateFormat) {
		List<String> result = new ArrayList<>();
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月");
		String str_ym_end = dateEnd.format(formatter);
		String str_ym_begin = dateBegin.format(formatter);
		result.add(str_ym_begin);
		while (!str_ym_begin.equals(str_ym_end)) {
			dateBegin = dateBegin.plusMonths(1);
			str_ym_begin = dateBegin.format(formatter);
			result.add(str_ym_begin);
		}
		return result;
	}
}
